<!DOCTYPE html>
<html lang="en">
<head>
    <title>交易结算设置</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <script src="../lib/layuimini/lib/layui-v2.5.5/layui.js"></script>
    <script src="../lib/layuimini/js/lay-config.js"></script>
    <link type="text/css" rel="stylesheet" href="layui/css/layui.css" media="all">
    <script type="text/javascript" src="layui/layui.js"></script>
</head>

<body>
<!--结算表头-->
<script type="text/html" id="userToolBar">
    <div style="margin-top: 0px;margin-left: 0px" >
        <form class="layui-form layui-col-space5">
            <div class="layui-inline layui-show-xs-block">
                <label class="layui-form-label layui-bg-gray" style="width: 110px;text-align: center">成交日期</label>
                <div class="layui-inline layui-show-xs-block">
                    <input class="layui-input"  autocomplete="off" type="date" placeholder="请输入成交日期" name="dealTime" id="dealTime">
                </div>
            </div>
            <div class="layui-inline layui-show-xs-block">
                <label class="layui-form-label layui-bg-gray" style="width: 110px;text-align: center">交易方式</label>
                <div class="layui-inline layui-show-xs-block">
                    <select name="dealWay" id="dealWay">
                        <option value="0" placeholder="请选择"></option>
                        <option value="1">买入</option>
                        <option value="2">卖出</option>
                        <option value="3">分红</option>
                        <option value="4">送股</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline layui-show-xs-block">
                <button class="layui-btn layui-btn-primary"  lay-submit="" lay-filter="select" lay-event="select"><i class="layui-icon">&#xe615;</i>搜索</button>
            </div>
            <div class="layui-inline layui-show-xs-block">
                <button class="layui-btn layui-btn-normal"  type="button" lay-submit="dealData" lay-filter="search" lay-event="search" name="dealData" id="dealData" onclick="return false;" >结算</button>
            </div>
        </form>
        <ul class="layui-tab-title" style="border-bottom-color: #D0D0D0">
            <li class="layui-this" lay-id="no" style="color:#FF00FF">未结算</li>
            <li class="layui-this" lay-id="yes">已结算</li>
        </ul>
    </div>
</script>

<!--反结算表头-->
<script type="text/html" id="userToolBar2">
    <div style="margin-top: 0px;margin-left: 0px" >
        <form class="layui-form layui-col-space5">
            <div class="layui-inline layui-show-xs-block">
                <label class="layui-form-label layui-bg-gray" style=" width: 110px;text-align: center">成交日期</label>
                <div class="layui-inline layui-show-xs-block">
                    <input class="layui-input"  autocomplete="off" type="date" placeholder="请输入成交日期" name="dealTime" id="dealTime2">
                </div>
            </div>
            <div class="layui-inline layui-show-xs-block">
                <label class="layui-form-label layui-bg-gray" style="width: 110px;text-align: center">交易方式</label>
                <div class="layui-inline layui-show-xs-block">
                    <select name="dealWay" id="dealWay2" >
                        <option value="0"placeholder="请选择"></option>
                        <option value="1">买入</option>
                        <option value="2">卖出</option>
                        <option value="3">分红</option>
                        <option value="4">送股</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline layui-show-xs-block">
                <button class="layui-btn layui-btn-primary" lay-submit="" lay-filter="select" lay-event="select"><i class="layui-icon">&#xe615;</i>搜索</button>
            </div>
            <div class="layui-inline layui-show-xs-block">
                <button class="layui-btn layui-btn-normal"  type="button" lay-submit="dealData" lay-filter="search2" lay-event="search2" name="dealData" id="dealData2" onclick="return false"; >反结算</button>
            </div>
        </form>
        <ul class="layui-tab-title" style="border-bottom-color: #D0D0D0">
            <li class="layui-this" lay-id="no">未结算</li>
            <li lay-id="yes" style="color:#FF00FF">已结算</li>
        </ul>
    </div>
</script>

<div class="layui-tab" lay-filter="test">
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <!--表格-->
            <table id="userTable" lay-filter="userTable"></table>
        </div>
        <div class="layui-tab-item">
            <table id="userTable2" lay-filter="userTable2"></table>
        </div>
    </div>
</div>

<script>
    layui.use(['element', 'form', 'table', 'layer', 'laydate'], function () {
        var layer = layui.layer;
        var $ = layui.$;
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;

        //未结算表格数据
        table.render({
            elem: '#userTable',
            url: 'SettlementMap',
            page: true,
            height: 'full-50',
            minLength:80,
            toolbar:'#userToolBar',
            cols: [
                [ //表头
                    {type: 'checkbox', fixed: 'left'}
                    ,{field:'dealId', title: '交易ID', hide: true}
                    ,{field:'seatId', title: '席位ID', hide: true}
                    ,{field:'fundId', title: '基金ID', hide: true}
                    ,{field:'dealTime', title: '交易日期'}
                    ,{field:'dealNumber', title: '交易数量'}
                    ,{field:'dealPrice', title: '交易单价'}
                    ,{field:'endMoney', title: '结算金额'}
                    ,{field:'dealMoney', title: '交易金额'}
                    ,{field:'endTime', title: '结算日期'}
                    ,{field:'cashId', title: '现金账号ID'}
                    ,{field:'securityId', title: '证券ID'}
                    ,{field:'brokerId', title: '券商ID'}
                    ,{field:'commissionFees', title: '佣金费用',hide: true}
                    ,{field:'transferFee', title: '过户费', hide: true}
                    ,{field:'stampDuty', title: '印花税', hide: true}
                    ,{field:'control', title: '征管费', hide: true}
                    ,{field:'handle', title: '经手费', hide: true}
                    ,{field:'dealWay', title: '交易方式', templet: function (Settlement) {
                        if (Settlement.dealWay == 1) {
                            return '买入';
                        } else if (Settlement.dealWay == 2) {
                            return '卖出';
                        }else if (Settlement.dealWay == 3) {
                            return '分红';
                        }else if (Settlement.dealWay == 4) {
                            return '送股';
                        }
                    }
                }
                    ,{fixed:'right', field: 'dealState', title: '交易状态' ,templet: function (SettlementFan) {
                        if (SettlementFan.dealState == 1) {
                            return '已结算';
                        } else if (SettlementFan.dealState == 2) {
                            return '未结算';
                        }
                    }}
                ]
            ]
        });
        //执行一个laydate实例
        laydate.render({
            elem: '#dealDate' //指定元素
        });
        laydate.render({
            elem: '#dealDate2' //指定元素
        });

        //已结算表格数据
        table.render({
            elem: '#userTable2',
            url: 'SettlementMapFan',
            page: true,
            height: 'full-100',
            minLength:80,
            toolbar:'#userToolBar2',
            cols: [
                [ //表头
                    {type: 'checkbox', fixed: 'left'}
                    ,{field:'dealId', title: '交易ID', hide: true}
                    ,{field:'seatId', title: '席位ID', hide: true}
                    ,{field:'fundId', title: '基金ID', hide: true}
                    ,{field:'dealTime', title: '交易日期'}
                    ,{field:'dealNumber', title: '交易数量'}
                    ,{field:'dealPrice', title: '交易单价'}
                    ,{field:'endMoney', title: '结算金额'}
                    ,{field:'dealMoney', title: '交易金额'}
                    ,{field:'endTime', title: '结算日期'}
                    ,{field:'cashId', title: '现金账号ID'}
                    ,{field:'securityId', title: '证券ID'}
                    ,{field:'brokerId', title: '券商ID'}
                    ,{field:'commissionFees', title: '佣金费用',hide: true}
                    ,{field:'transferFee', title: '过户费', hide: true}
                    ,{field:'stampDuty', title: '印花税', hide: true}
                    ,{field:'control', title: '征管费', hide: true}
                    ,{field:'handle', title: '经手费', hide: true}
                    ,{field:'securityInterest', title: '证券利息', hide: true}
                    ,{field:'dealWay', title: '交易方式', templet: function (Settlement) {
                        if (Settlement.dealWay == 1) {
                            return '买入';
                        } else if (Settlement.dealWay == 2) {
                            return '卖出';
                        }else if (Settlement.dealWay == 3) {
                            return '分红';
                        }else if (Settlement.dealWay == 4) {
                            return '送股';
                        }
                    }
                }
                    ,{fixed:'right', field: 'dealState', title: '交易状态' ,templet: function (Settlement) {
                        if (Settlement.dealState == 1) {
                            return '已结算';
                        } else if (Settlement.dealState == 2) {
                            return '未结算';
                        }
                    }}
                ]
            ]
        });
        //给工具条的结算添加事件
        table.on('toolbar(userTable)', function (obj) {

            switch (obj.event) {
                case "search":
                    //获得选中的对象
                    var checkStatus = table.checkStatus("userTable"); //idTest 即为基础参数 id 对应的值
                    // 其中 ID 为基础参数 id 对应的值（见：设定容器唯一ID）
                    var dataArr = checkStatus.data; //获取选中行的数据
                    //转json格式
                    var dealData=JSON.stringify(dataArr);
                    if (dataArr.length == 0) {
                        layer.msg("请先选中数据");
                    }
                    else {
                        layer.confirm('真的要结算嘛', function () {
                            //向服务端发送结算指令
                            $.post("updateSettlementFan","settlement="+dealData,function(msg){
                                if(msg>0){
                                    table.reload('userTable');
                                    table.reload('userTable2');  /!*渲染刷新*!/
                                    layer.closeAll();
                                    layer.msg('结算成功',{
                                        title : '提示',
                                        area : [ '200px',
                                            '140px' ],
                                        btn : [ '知道了' ]
                                    });
                                }
                                else{
                                    layer.closeAll();
                                    layer.msg('结算失败',{
                                        title : '提示',
                                        area : [ '200px',
                                            '140px' ],
                                        btn : [ '知道了' ]
                                    });
                                }
                            });
                            return false;
                        });
                    }
                    break;
                case 'select':
                    // alert("搜索");
                    var dealTime= $("#dealTime").val();
                    var dealWay= $("#dealWay").val();
                    //表格的重新加载事件
                    table.reload('userTable', {
                        method: 'post'
                        , where: {
                            'dealTime': dealTime,
                            'dealWay': dealWay
                        }
                        , page: {
                            curr: 1
                        }
                    });
                    laydate.render({
                        elem: '#dealDate' //指定元素
                    });
                    $("#dealTime").val(dealTime);
                    $("#dealWay").val(dealWay);
                    break;
            }
        });
        //给工具条的反结算添加事件
        table.on('toolbar(userTable2)', function (obj) {
            switch (obj.event) {
                case "search2":
                    //获得选中的对象
                    var checkStatus = table.checkStatus("userTable2"); //idTest 即为基础参数 id 对应的值
                    // 其中 ID 为基础参数 id 对应的值（见：设定容器唯一ID）
                    var dataArr = checkStatus.data; //获取选中行的数据
                    //转json格式
                    var dealData=JSON.stringify(dataArr);
                    if (dataArr.length == 0) {
                        layer.msg("请先选中数据");
                    }
                    else {
                        layer.confirm('真的要反结算嘛', function () {
                            layer.close();
                            //向服务端发送删除指令
                            $.post("updateSettlement","settlement="+dealData,function(msg){
                                if(msg>0){
                                    table.reload('userTable2');
                                    table.reload('userTable');  /*渲染刷新*/
                                    layer.closeAll(); //关闭所有层
                                    layer.msg('反结算成功',{
                                        title : '提示',
                                        area : [ '200px',
                                            '140px' ],
                                        time : 0,
                                        btn : [ '知道了' ]
                                    });
                                }
                                else{
                                    layer.closeAll();
                                    layer.msg('反结算失败',{
                                        title : '提示',
                                        area : [ '200px',
                                            '140px' ],
                                        time : 0,
                                        btn : [ '知道了' ]
                                    });
                                }
                            });
                            return false;
                        });
                    }
                    break;
                case 'select':
                    var dealTime= $("#dealTime2").val();
                    var dealWay= $("#dealWay2").val();
                    //表格的重新加载事件
                    table.reload('userTable2', {
                        method: 'post'
                        , where: {
                            'dealTime': dealTime,
                            'dealWay': dealWay
                        }
                        , page: {
                            curr: 1
                        }
                    });
                    laydate.render({
                        elem: '#dealTime2' //指定元素
                    });
                    $("#dealTime").val(dealTime);
                    $("#dealWay").val(dealWay);
                    break;
            }
        });
    });
</script>
</body>
</html>